using System;
using System.Linq;
using System.Collections.Generic;
using Widgetsphere.Autos.EFDAL;

namespace Widgetsphere.AutoAggregate.Website.Objects
{
    public static class GeoHelper
    {
        private const string key = "ABQIAAAAUxIFuN1kkQRWbAItsjccZxTr_ws5udgvNfWUWzW6E6AJwuXnsRT6NdI2HlRUs5X3tUZk_O0SmGdFyg";
        private const string urlFormat = "http://maps.google.com/maps/geo?q={0},+{1},+{2},+{3}&output=csv&key=" + key;

        public static GeoCode GetGeoFromZip(string zip)
        {
            using (var context = new AutosEntities())
            {
                GeoCode retval = null;
                var zipItem = context.Zip.FirstOrDefault(x => x.Name == zip);
                if (zipItem != null)
                {
                    retval = new GeoCode();
                    retval.Latitude = (decimal)zipItem.Latitude;
                    retval.Longitude = (decimal)zipItem.Longitude;
                }
                return retval;
            }
        }

        //public static string GetZipFromGeo(decimal latitude, decimal longitude)
        //{
        //	//Look and find the zip from the lat/long
        //	foreach (string zip in _cachedQueries.Keys)
        //	{
        //		GeoCode geoCode = _cachedQueries[zip];
        //		if ((geoCode.Latitude == latitude) && (geoCode.Longitude == longitude))
        //		{
        //			return zip;
        //		}
        //	}

        //	string retval = GeoHelper.GetZipFromGeo(latitude, longitude);
        //	if (retval != "")
        //		return retval;

        //	return "[Unknown]";

        //}

    }

}